<?php

namespace app\admin\controller;

use app\common\controller\Admin;

/**
 * 站内信
 * Class Msg
 * @package app\admin\controller
 */
class Msg extends Admin
{
    /**
     * 消息列表
     * @return mixed
     */
    public function index()
    {
        $param = $this->request->param();
        $map = [];

//        $map['status'] = array('egt', 0);
//        if (isset($param['nickname']) && $param['nickname']) {
//            $map['nickname'] = array('like', '%' . $param['nickname'] . '%');
//        }
//        if (isset($param['username']) && $param['username']) {
//            $map['username'] = array('like', '%' . (string)$param['nickname'] . '%');
//        }

        if (isset($param['uid']) && $param['uid']) {
            $map['uid'] = intval($param['uid']);
        }

        $list = model('UserMsg')->where($map)->order('id desc')
            ->paginate(15, false, array(
                'param' => $param
            ));

        $data = array(
            'list' => $list,
            'page' => $list->render(),
            'param' => $param
        );
        $this->assign($data);
        $this->setMeta('用户站内信');
        return $this->fetch();
    }

    /*
     * 删除
     */
    public function del($id)
    {
        $uid = array('IN', is_array($id) ? implode(',', $id) : $id);
        model('UserMsg')->where(array('id' => $uid))->delete();
        $this->success('删除信息成功！');
    }

}